package repositories

import (
	"gitee.com/cjf8134/bbs_serve/internal/pkg/models"
	"gitee.com/cjf8134/bbs_serve/internal/pkg/requests"
	"gitee.com/cjf8134/bbs_serve/internal/pkg/utils/constutil"
)

// Linklist  友情链接列表
func (r *MysqlApiServeRepository) LinkList(req *requests.LinkList) (link []*models.Link, err error) {
	model := r.db.Model(models.Link{})
	if req.Limit <= 0 {
		req.Limit = constutil.DefaultMaxPageSize
	}
	if req.Limit > constutil.DefaultMaxPageSize {
		req.Limit = constutil.DefaultMaxPageSize
	}
	if req.Page <= 0 {
		req.Page = 0
	}
	order := "id desc"
	err = model.Offset(req.Page * req.Limit).Order(order).Limit(req.Limit).Find(&link).Error
	return
}
